<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px' , minHeight: '230px' }">
          <div class="header">
            <span>总答题数量</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning" />
            </el-tooltip>
          </div>
          <div class="total">
            260,560
          </div>
          <div class="trends">
            <span>周同比 12% <i class="el-icon-caret-top" /></span>
            <span>日环比 11% <i class="el-icon-caret-bottom" /></span>
          </div>
          <div class="hr" />
          <div class="footer">
            <span>日答题数量</span> <span>12,423</span>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px' , minHeight: '230px' }">
          <div class="header">
            <span>试题方向</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning" />
            </el-tooltip>
          </div>
          <div class="chart">
            <RaddarChart />
          </div>
          <div class="hr" />
          <div class="footer">
            <span>试题访问量</span> <span>10,234</span>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px' , minHeight: '230px' }">
          <div class="header">
            <span>试题学科分布</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning" />
            </el-tooltip>
          </div>
          <div class="chart">
            <pie-chart />
          </div>
          <div class="hr" />
          <div class="footer">
            <span>前端试题数量</span> <span>5,234</span>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px' , minHeight: '230px' }">
          <div class="header">
            <span>上周试题新增</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning" />
            </el-tooltip>
          </div>
          <div class="chart">
            <BarChart />
          </div>
          <div class="hr" />
          <div class="trends">
            <span>上周新增总量 1,234</span>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <br>
    <el-card class="sales-card">
      <div class="header"><span>前端与JAVA学科走势图</span></div>
      <el-tabs v-model="activeName" @tab-click="handleSetLineChartData">
        <el-tab-pane label="前端" name="newVisitis" />
        <el-tab-pane label="JAVA" name="messages" />
        <el-row :gutter="20">
          <el-col :xs="24" :sm="16">
            <div class="chart">
              <line-chart :chart-data="lineChartData" />
            </div>
          </el-col>
          <el-col :xs="24" :sm="8">
            <div class="table">
              <h4>学科试题数量排名</h4>
              <ul>
                <li>
                  <el-row v-for="(item, index) in salesTable" :key="'sals-'+index" class="row">
                    <el-col :span="3"><div :class="[item.num > 3 ? 'light' : '','circular']">{{ item.num }}</div></el-col>
                    <el-col :span="16"> {{ item.title }} </el-col>
                    <el-col :span="5"> {{ item.val }} </el-col>
                  </el-row>
                </li>
              </ul>
            </div>
          </el-col>
        </el-row>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import LineChart from './components/dashboardLineChart.vue'
import RaddarChart from './components/dashboardRaddarChart.vue'
import PieChart from './components/dashboardPieChart.vue'
import BarChart from './components/dashboardBarChart.vue'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165, 100, 120, 161, 134, 105, 160, 165]
  }
}

export default {
  name: 'DashBoard',
  components: {
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      activeName: 'newVisitis',
      datePicker: '',
      salesTable: [],
      hotsTableData: [],
      radioArea: '全渠道'
    }
  },
  computed: {},
  created() {
    for (let i = 1; i < 9; i++) {
      this.salesTable.push(
        {
          num: i,
          title: `学科 ${i} `,
          val: '323,234'
        }
      )
    }
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type.name]
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-container {
  margin: 10px;
}

.box-card {
  padding: 5px 10px;
  .header {
    height: 25px;
    span {
      color: #97a8be;
      font-size: 14px;
    }
    .item {
      color: #97a8be;
      float: right;
      padding: 3px 0;
    }
  }
  .total {
    font-size: 30px;
    height: 140px;
    line-height: 140px;
    padding-left: 20px;
  }
  .trends {
    height: 22px;
    font-size: 14px;
    span {
      display: inline;
      i {
        color: red;
      }
    }
    span:last-child {
      margin-left: 20px;
      display: inline;
      i {
        color: green;
      }
    }
  }
  .chart {
    height: 160px;
  }
  .hr {
    border-top: 1px solid #e8e8e8;
    margin: 0px 0px 10px 0px;
  }
  .footer {
    span {
      font-size: 14px;
      line-height: 22px;
    }
    span:last-child {
      margin-left: 8px;
      color: rgba(0, 0, 0, 0.85);
    }
  }
}

.sales-card {
  position: relative;
  .header {
    position: absolute;
    right: 20px;
    top: 15px;
    z-index: 1;
  }
  .chart {
    widows: 100%;
    height: 300px;
  }
  .table {
    color: rgba(0,0,0,.65);
    h4 {
      color: #000;
      font-weight: 500;
    }
    ul {
      list-style: none;
      margin: 0px;
      padding: 0px;
      .row {
        margin-bottom: 10px;
      }
    }
    .circular {
      width: 20px;
      height: 20px;
      background-color: #314659;
      color: #fff;
      text-align: center;
      font-size: 12px;
      line-height: 20px;
      font-weight: 600;
      border-radius:50%
    }
    .light {
      background-color: #f5f5f5;
      color: rgba(0,0,0,.65);
    }
  }
}
</style>
